using UnityEngine;

namespace Gj
{
    public static class ScreenTools
    {
        public enum Type
        {
            Full,
            Size,
            Quality,
            Resolution,
            FrameRate
        }

        private static readonly ScreenSettings setting;

        static ScreenTools()
        {
            setting = LoadSettings();
        }

        private static ScreenSettings LoadSettings()
        {
            var loadedSettings = (ScreenSettings)Resources.Load("ScreenSettings", typeof(ScreenSettings));
            if (loadedSettings == null)
            {
                loadedSettings = ScriptableObject.CreateInstance<ScreenSettings>();
                Debug.LogError("ScreenSettings is not exist (Resources)");
            }

            return loadedSettings;
        }

        public static string GetName(Type type, int index)
        {
            switch (type)
            {
                case Type.Full:
                    return setting.FullItems[index].name;
                case Type.Size:
                    return setting.SizeItems[index].name;
                case Type.Quality:
                    return setting.QualityItems[index].name;
                case Type.Resolution:
                    return setting.ResolutionItems[index].name;
                case Type.FrameRate:
                    return setting.FrameRateItems[index].name;
            }

            return "";
        }

        public static int GetValue(Type type, int index)
        {
            switch (type)
            {
                case Type.Full:
                    return setting.FullItems[index].value;
                case Type.Size:
                    return setting.SizeItems[index].value;
                case Type.Quality:
                    return setting.QualityItems[index].value;
                case Type.Resolution:
                    return setting.ResolutionItems[index].value;
                case Type.FrameRate:
                    return setting.FrameRateItems[index].value;
            }

            return 0;
        }

        public static int GetCount(Type type)
        {
            switch (type)
            {
                case Type.Full:
                    return setting.FullItems.Length;
                case Type.Size:
                    return setting.SizeItems.Length;
                case Type.Quality:
                    return setting.QualityItems.Length;
                case Type.Resolution:
                    return setting.ResolutionItems.Length;
                case Type.FrameRate:
                    return setting.FrameRateItems.Length;
            }

            return 0;
        }
    }
}